function [engimg time] = imenergy( origimg,nRows,ncols )
%IMENERGY computes the energy haralick descriptor of an image
%   Function IMENERGY accepts an input image computing a co-occurrence 
%   matrix with  angle = 0 and distance = 1 using a neighborhood size of 
%   mRows x mCols pixels  Finally an energy texture image was constructed
%   from the energy value of all pixels in the image
%
%
% Calling sequence:
%  EnergyImage=imenergy(InputImage,SizeOfRowOfNeigbourhood,SizeOfRowOfNeigbourhood)
%
% Define variables:
%    origimg ---------- input image
%    mRoews  ---------- Size Of Rows Of Neigbourhood
%    mCols   ---------- Size Of Cols Of Neigbourhood
%
%
%
% Record of revisions:
%       Date                Programmer              Description of change           
%       ====                ==========              =====================
%       2/24/2012           H.Ayad                   Original Code
%
%
tic;
narginchk(3,3);    % validate # of input arguments i.e is min=max=3  
f=origimg;

h=size(f,1);
w=size(f,2);

g=im2double(f);

rowoffset=floor(nRows/2);
coloffset=floor(ncols/2);

rowBoundary = h-rowoffset;
colBoundary = w-coloffset;

for r=rowoffset+1:rowBoundary
    
    for c=coloffset+1:colBoundary
        
       s=f(r-rowoffset:r+rowoffset,c-coloffset:c+coloffset);
       glcm=graycomatrix(s);
       stats=graycoprops(glcm, 'Energy');
       g(r,c)=stats.Energy;
        
        
    end
    



end

engimg=g;
time=toc;